package com.jorado.etl.repository;

import com.jorado.search.core.service.Exporter;
import org.apache.ibatis.annotations.*;
import org.springframework.context.annotation.Description;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Mapper
@Repository
@Description("Solr数据库职位导出器")
public interface SolrPositionRepository extends Exporter {

    @Select("SELECT count(*) FROM jorado.Solr_Position(nolock)")
    @Override
    long count();

    @Select("select * from (" +
            "select row_number() over(" +
            "order by AutoID asc" +
            ") as num,JOB_TITLE,JOB_TYPE_NAME,INDUSTRY_NAME from jorado.Solr_Position) " +
            "tbl where num>=#{start} and num<=(#{start}+#{rows})")
    @Override
    List<Map<String, Object>> listDatas(@Param("start") int start, @Param("rows") int rows);

    @Insert("INSERT INTO jorado.Solr_Position (ID,JOB_TITLE,JOB_TYPE,JOB_TYPE_NAME,JOB_DESC,INDUSTRY_ID,INDUSTRY_NAME,COMPANY_ID,COMPANY_NAME,COMPANY_NAME_SHORT) " +
            "VALUES (#{id},#{jobTitle},#{jobType},#{jobTypeName},#{jobDescription},#{industryId},#{industryName},#{companyId},#{companyName},#{companyShortName})")
    void insert(@Param("id") String id, @Param("jobTitle") String jobTitle, @Param("jobType") String jobType, @Param("jobTypeName") String jobTypeName, @Param("jobDescription") String jobDescription, @Param("industryId") String industryId, @Param("industryName") String industryName, @Param("companyId") String companyId, @Param("companyName") String companyName, @Param("companyShortName") String companyShortName);

    @Delete("DELETE from jorado.Solr_Position")
    void clear();
}

